package com.appheader.rongmaphone.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.appheader.rongmaphone.MainActivity;
import com.appheader.rongmaphone.R;
import com.appheader.rongmaphone.cache.preference.PreferenceUtil;

public class SplashActivity extends AppCompatActivity {
    private Handler handler = new Handler();
//    private static SharedPreferences sharedPreferences;
    private static String session_id;
    private PreferenceUtil preferenceUtil;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide();
        setContentView(R.layout.activity_splash);
        preferenceUtil = new PreferenceUtil(getApplicationContext());
        String userStr = preferenceUtil.getString("userStr");
        //可以获取到
        Log.e("sharedpreference", "run: ---------" + userStr);
        loadMethod();
    }

    private void loadMethod() {
        new Thread(new Runnable() {
            @Override
            public void run() {

//                boolean isFirst = sharedPreferences.getBoolean("isFirst", false);
                boolean isFirst = preferenceUtil.getBoolean("isFirst");
                Log.e("sPLASHTAG", "run: "+isFirst);

                if (isFirst) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
                    startActivity(intent);
                    finish();
                }
//                }
            }
        }).start();


    }
}
